<template>
  <div class="sidebar">
    <el-menu
      class="sidebar-el-menu"
      :default-active="onRoutes"
      :collapse="collapse"
      background-color="#104E8B"
      text-color="#fff"
      active-text-color="#fff"
      unique-opened
      router
    >
      <template v-for="item in items">
        <template v-if="item.subs">
          <el-submenu :index="item.index" :key="item.index">
            <template slot="title">
              <i :class="item.icon"></i>
              <span slot="title">{{ item.title }}</span>
            </template>
            <template v-for="subItem in item.subs">
              <el-submenu
                v-if="subItem.subs"
                :index="subItem.index"
                :key="subItem.index"
              >
                <template slot="title">{{ subItem.title }}</template>
                <el-menu-item
                  v-for="(threeItem, i) in subItem.subs"
                  :key="i"
                  :index="threeItem.index"
                  >{{ threeItem.title }}</el-menu-item
                >
              </el-submenu>
              <el-menu-item
                v-else
                :index="subItem.index"
                :key="subItem.index"
                >{{ subItem.title }}</el-menu-item
              >
            </template>
          </el-submenu>
        </template>
        <template v-else>
          <el-menu-item :index="item.index" :key="item.index">
            <i :class="item.icon"></i>
            <span slot="title">{{ item.title }}</span>
          </el-menu-item>
        </template>
      </template>
    </el-menu>
  </div>
</template>

<script>
import bus from '../common/bus'
export default {
  data () {
    var functionItems = []
    if (localStorage.getItem('LOGIN_NAME') === 'bh') {
      functionItems.push({
        icon: 'el-icon-location',
        index: 'Monitoring',
        title: '车辆监控'
      })
      functionItems.push({
        icon: 'el-icon-setting',
        index: 'vehicle',
        title: '车辆基础信息'
      })
      functionItems.push({
        icon: 'el-icon-setting',
        index: 'ExcelRubbishCheckInfo',
        title: '车辆行驶时长里程统计'
      })
    }
    if (localStorage.getItem('LOGIN_NAME') === 'adminys') {
      functionItems = [{
        icon: 'el-icon-location',
        index: 'Monitoring',
        title: '车辆监控'
      },
      {
        icon: 'el-icon-s-order',
        index: 'StatisticsDistrict',
        title: '吨位统计'
      },
      {
        icon: 'el-icon-s-order',
        index: 'CarInOutStatistics',
        title: '车辆进出厂统计'
      },
      {
        icon: 'el-icon-data-analysis',
        index: 'PictureDistrict',
        title: '图形统计'
      },
      {
        icon: 'el-icon-place',
        index: 'rubbishThePlayback',
        title: '垃圾点收集遗漏轨迹图'
      }]
      functionItems.push({
        icon: 'el-icon-s-order',
        index: 'WeightQTable',
        title: '称重查询',
        subs: [
          {
            index: 'ByPointNew',
            title: '挂桶点位称重'
          }, {
            index: 'ByPointNewHold',
            title: '整车点位称重'
          }, {
            index: 'ByCarNew',
            title: '挂桶车辆称重'
          }, {
            index: 'ByCarNewHold',
            title: '整车车辆称重'
          }, {
            index: 'WeightAlarm',
            title: '称重报警'
          }]
      })
      functionItems.push({
        icon: 'el-icon-s-order',
        index: 'PlannedRoute',
        title: '路线规划',
        subs: [
          {
            index: 'PlannedRoute',
            title: '路线规划'
          }, {
            index: 'ShowRoute',
            title: '路线展示'
          }, {
            index: 'RouteTimeStatistics',
            title: '规划路线分析'
          }, {
            index: 'RouteStatistics',
            title: '收运点位分析'
          }, {
            index: 'RouteStatisticsToday',
            title: '当日收运点位分析'
          // }, {
          //   index: 'ShowRoute1',
          //   title: '区域路线规划'
          }]
      })
      functionItems.push({
        icon: 'el-icon-setting',
        index: 'vehicle',
        title: '车辆基础信息'
      })
      functionItems.push({
        icon: 'el-icon-setting',
        index: 'place',
        title: '垃圾点基础信息'
      })
    }
    if (localStorage.getItem('LOGIN_NAME') === 'yanshiclz') {
      functionItems = [{
        icon: 'el-icon-location',
        index: 'Monitoring',
        title: '车辆监控'
      },
      {
        icon: 'el-icon-s-order',
        index: 'StatisticsDistrict',
        title: '吨位统计'
      },
      {
        icon: 'el-icon-s-order',
        index: 'CarInOutStatistics',
        title: '车辆进出厂统计'
      },
      {
        icon: 'el-icon-data-analysis',
        index: 'PictureDistrict',
        title: '图形统计'
      },
      {
        icon: 'el-icon-place',
        index: 'rubbishThePlayback',
        title: '垃圾点收集遗漏轨迹图'
      }]
      functionItems.push({
        icon: 'el-icon-s-order',
        index: 'WeightQTable',
        title: '称重查询',
        subs: [
          {
            index: 'ByPointNew',
            title: '挂桶点位称重'
          }, {
            index: 'ByPointNewHold',
            title: '整车点位称重'
          }, {
            index: 'ByCarNew',
            title: '挂桶车辆称重'
          }, {
            index: 'ByCarNewHold',
            title: '整车车辆称重'
          }, {
            index: 'WeightAlarm',
            title: '称重报警'
          }]
      })
      functionItems.push({
        icon: 'el-icon-s-order',
        index: 'PlannedRoute',
        title: '路线规划',
        subs: [
          {
            index: 'PlannedRoute',
            title: '路线规划'
          }, {
            index: 'ShowRoute',
            title: '路线展示'
          }, {
            index: 'RouteTimeStatistics',
            title: '规划路线分析'
          }, {
            index: 'RouteStatistics',
            title: '收运点位分析'
          }, {
            index: 'RouteStatisticsToday',
            title: '当日收运点位分析'
          }, {
            index: 'ShowRoute1',
            title: '区域路线规划'
          }]
      })
      functionItems.push({
        icon: 'el-icon-setting',
        index: 'vehicle',
        title: '车辆基础信息'
      })
      functionItems.push({
        icon: 'el-icon-setting',
        index: 'place',
        title: '垃圾点基础信息'
      })
      functionItems.push({
        icon: 'el-icon-discount',
        index: 'PlaceFactoryHome',
        title: '处理站管理'
      })
      functionItems.push({
        icon: 'el-icon-box',
        index: 'ProcessingCapacity',
        title: '处理量统计',
        subs: [
          {
            index: 'ProcessingCapacityQ',
            title: '处理量按区统计'
          }, {
            index: 'ProcessingCapacityZ',
            title: '处理量按站统计'
          }]
      })
      functionItems.push({
        icon: 'el-icon-wallet',
        index: 'OperatingCosts',
        title: '运行费统计',
        subs: [
          {
            index: 'OperatingCostsQ',
            title: '运行费按区统计'
          }, {
            index: 'OperatingCostsZ',
            title: '运行费按站统计'
          }]
      })
      // functionItems.push({
      //     icon: 'el-icon-setting',
      //     index: 'TrackRoute',
      //     title: '路线规划'
      // })
      // functionItems.push({
      //     icon: 'el-icon-place',
      //     index: 'HUABAO_CCTV',
      //     title: '视频监控'
      // })
    }
    return {
      collapse: false,
      items: functionItems
    }
  },
  computed: {
    onRoutes () {
      return this.$route.path.replace('/', '')
    }
  },
  created () {
    // 通过 Event Bus 进行组件间通信，来折叠侧边栏
    bus.$on('collapse', msg => {
      this.collapse = msg
      bus.$emit('collapse-content', msg)
    })
  }
}
</script>

<style scoped lang="less">
.sidebar {
  display: block;
  position: absolute;
  left: 0;
  top: 70px;
  bottom: 0;
  overflow-y: scroll;
}
.sidebar::-webkit-scrollbar {
  width: 0;
}
.sidebar-el-menu:not(.el-menu--collapse) {
  width: 250px;
}
.sidebar > ul {
  height: 100%;
}
.el-menu-item {
  font-weight: bold;
}
/deep/.el-submenu__title {
  font-weight: bold;
}
.el-menu-item.is-active {
  font-weight: bold;
  background-color: #0d3e6f !important;
}
</style>
